﻿using GeekDesk.Control.UserControls.Push;
using GeekDesk.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace GeekDesk.Control.Windows
{
    /// <summary>
    /// PushBasicWindow.xaml 的交互逻辑
    /// </summary>
    public partial class PushBasicWindow : IWindowCommon
    {
        CSDNControl csdnControl=new CSDNControl();
        APIControl apiControl;
        public static string SearchString;
        public PushBasicWindow()
        {
            InitializeComponent();
            ShowPanel.Visibility = Visibility.Hidden;
            //this.Topmost = true;
        }

       

        //关闭
        private void Close_Button_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }


        //private static Window window = null;
        //public static void Show()
        //{
        //    if (window == null || !window.Activate())
        //    {
        //        window = new PushBasicWindow();
        //    }
        //    window.Show();
        //    window.Activate();
        //    Keyboard.Focus(window);
        //}

        //移动窗口
        Point pressedPosition;
        bool isDragMoved = false;

        private void Window_PreviewMouseLeftBottonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            pressedPosition = e.GetPosition(this);
        }

        private void Window_PreviewMouseMove(object sender, MouseEventArgs e)
        {
            if (Mouse.LeftButton == MouseButtonState.Pressed && e.GetPosition(this) != pressedPosition)
            {
                isDragMoved = true;
                DragMove();
            }
        }

        private void Window_PreviewLeftBottonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (isDragMoved)
            {
                isDragMoved = false;
                e.Handled = true;
            }
        }

        private void HotPassage_Botton_Click(object sender, RoutedEventArgs e)
        {
            ShowCard.Content = csdnControl;
            csdnControl.Visibility = Visibility.Visible;
            ShowPanel.Visibility = Visibility.Visible;
        }
        private void API_Button_Click(object sender, RoutedEventArgs e)
        {
            getSearch();
            if (SearchString == null)
            {
                MessageBox.Show("请输入查询内容");
            }
            else
            {
                apiControl = new APIControl(SearchString);
               
                ShowCard.Content = apiControl;
                apiControl.Visibility = Visibility.Visible;
                ShowPanel.Visibility = Visibility.Visible;
            }
            
        }

        private void getSearch()
        {
            SearchString= Search.Text;
        }
       

        //private void GitHub_Botton_Click(object sender, RoutedEventArgs e)
        //{
        //    ShowCard.Content = pushControl;
        //    pushControl.Visibility = Visibility.Visible;
        //    ShowPanel.Visibility = Visibility.Visible;
        //}

        public void OnKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Escape)
            {
                this.DataContext = null;
                this.Close();
            }
        }


        
    }
}
